package org.example.homeWork;

import java.util.Scanner;

/**
 * @AUTHOR 尹书岿
 * @DATE 2024/12/9 18:10
 * @DESCRIBE
 */
public class home16{
     public static void main(String[] args) {
          Scanner sc = new Scanner(System.in);
          //M：1 0 X 9 8 7 6 5 4 3 2
          char[] M = {'1','0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
          //{7，9，10，5，8，4，2，1，6，3，7，9，10，5，8，4，2}
          int[] nums = {7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
          int n = sc.nextInt();
          sc.nextLine();
          String[] str = new String[n];

          boolean flag = true;

          for (int i = 0; i < n;i++){
               str[i] = sc.nextLine();
          }

          loop:for(int i = 0; i < n ; i++){
               int sum = 0;
               for (int j = 0 ; j < 17 ;j++){
                    if (str[i].charAt(j) < '0' || str[i].charAt(j) > '9'){
                         System.out.println(str[i]);
                         flag = false;
                         continue loop;
                    }
                    sum += (str[i].charAt(j) - '0') * nums[j];
               }
               if (M[sum % 11] != str[i].charAt(17)){
                    System.out.println(str[i]);
                    flag = false;
               }

          }
          if (flag){
               System.out.println("All passed");
          }
     }

}
